package com.ruoyi.iot.listener;


import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.ruoyi.iot.service.IDeviceDataService;
import com.ruoyi.iotcommon.constant.RocketTopicConstant;
import com.ruoyi.iotcommon.domain.DeviceDataMessage;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;

/**
 * 设备上报数据监听器
 */
@Slf4j
@Service
@RocketMQMessageListener( topic = RocketTopicConstant.DEVICE_DATA, consumerGroup = "iot-core-device-data")
public class DeviceDataListener implements RocketMQListener<DeviceDataMessage>{

 
    @Resource
    IDeviceDataService deviceDataService;

    @Override
    public void onMessage(DeviceDataMessage message) {
        log.info("iot-core 收到设备上报数据:{}", JSON.toJSONString(message));
        // 插入时序数据库,也可以多线程异步插入
        deviceDataService.insertDevicePropertyData(message);
    }
    
}
